var prefix = "/fleet";
//var moduleFlag = '[[${moduleFlag}]]';

$(function () {
    load();
    $("#btn-search").click(function(){
        $("#exampleTable").bootstrapTable('refresh');
    });

});

function load() {
    $('#exampleTable').bootstrapTable(
        {
            method: 'post',
            url: prefix + "/list.do",
            iconSize: 'outline',
            toolbar: '#exampleToolbar',
            striped: true,
            dataType: "json",
            pagination: true,
            clickToSelect: true,
            pageSize: 10,
            pageNumber: 1,
            showColumns: false,
            sidePagination: "server",
            paginationLoop: false,
            contentType: "application/x-www-form-urlencoded",
            // cache : false,
            // dataType : "json",
            // contentType : "application/x-www-form-urlencoded",
            // toolbarAllgn : "left",
            // pagination : true,
            // sidePagination : "server",
            // pageNumber : 1,
            // pageSize : 5,
            // pageList : [ 3, 5, 7, 9, 11 ],
            // locale : "zh-CN",
            queryParams: function (params) {
                return {
                    pCode: $("#pCode").val(),
                    limit: params.limit,
                    offset: params.offset
                };
            },
            onClickRow:function(row, $element){
                $element.addClass('info').siblings().removeClass('info').end();
            },
            /* onDblClickRow: function (row, $element, field) {
                 view(row.id);
             },*/
            columns: [
                {
                    field: '',
                    formatter: orderFormatter,
                    title: '机型系列',
                    align: 'center',
                    width: '40'
                },
                {
                    field: 'acType',
                    title: '机型'
                },

                {
                    field: 'acTypeLong',
                    title: '长机型'
                },
                {
                    field: 'remarks',
                    title: '备注'
                },

                {
                    title: '操作',
                    align: 'center',
                    visible: isShowOperation(),
                    formatter: function (value, row, index) {
                        return [
                            '<a class="' + p_edit + '" href="#" title="编辑" onclick="edit(\'' + row.id + '\')">',
                            '<i class="glyphicon glyphicon-edit"></i>',
                            '</a>&nbsp;&nbsp;',
                            '<a class="' + p_delete + '" href="#" title="删除" onclick="remove(\''+ row.acTypeLong + '\')">',
                            '<i class="glyphicon glyphicon-remove  text-danger"></i>',
                            '</a>&nbsp;&nbsp;'
                        ].join('');
                    }
                }]
        })
}

//是否有权限显示 '操作' 列
function isShowOperation() {
    return (p_edit != 'hidden' || p_delete != 'hidden');
}

//刷新
function reload() {
    $("#pcode").val("");
    $("#exampleTable").bootstrapTable('refresh');
}

//增加
function add() {
    layer.open({
        type: 2,
        title: '新增',
        shadeClose: false, // 点击遮罩关闭层
        area: ['500px', '400px'],
        content : prefix + '/add.do'
    });
}

//编辑
function edit(id) {

    layer.open({
        type: 2,
        title: '编辑',
        shadeClose: false, // 点击遮罩关闭层
        area: ['500px', '400px'],
        content: prefix + '/edit.do?id=' + id
    });

}

//查看
function view(id) {
    layer.open({
        type: 2,
        title: '查看',
        shadeClose: false, // 点击遮罩关闭层
        area: ['500px', '400px'],
        content: prefix + '/view.do?id=' + id
    });
}

//删除
function remove(id) {
    layer.confirm('确定要删除选中的记录？', {
        btn: ['确定', '取消']
    }, function () {
        $.ajax({
            url: prefix + "/delete.do",
            type: "post",
            data: {
                'id': id
            },
            success: function (r) {
                if (r.code == 0) {
                    layer.msg(r.msg);
                    reload();
                } else {
                    layer.msg(r.msg);
                }
            }
        });
    })
}
